import { getListApi, addUserApi, deleteUserApi, updateUserApi, uploadApi } from '../../api/audit/index'
export default {
    namespaced: true,
    state: {
        tableData: [],
        total: 0,
        currentPage: 1,
        pageSize: 3
    },
    mutations: {
        SET_DATA(state, val) {
            state.tableData = val.data
            state.total = val.total
        },
        CURRENTPAGE(state, val) {
            state.currentPage = val
        },
        PAGESIZE(state, val) {
            state.pageSize = val
        }
    },
    actions: {
        async getList({ commit, state }, query) {
            const r = await getListApi({ currentPage: state.currentPage - 1, pageSize: state.pageSize, query })
            commit('SET_DATA', { data: r.data, total: r.total })
        },

        async addUser({ dispatch }, data) {
            await addUserApi(data)
            dispatch('getList')
        },

        async deleteUser({ dispatch }, data) {
            await deleteUserApi(data)
            dispatch('getList')
        },

        async updateUser({ dispatch }, data) {
            await updateUserApi(data)
            dispatch('getList')
        },

        async upload(context,data){
            await uploadApi(data)
        } 
    },
    getters: {}
}